package com.hctg.forced2sleep.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

import com.actor.myandroidframework.utils.LogUtils;
import com.actor.myandroidframework.utils.toaster.ToasterUtils;
import com.blankj.utilcode.util.BarUtils;
import com.blankj.utilcode.util.DeviceUtils;
import com.hctg.forced2sleep.adapter.MainAdapter;
import com.hctg.forced2sleep.databinding.ActivityMainBinding;
import com.hctg.forced2sleep.db.AppLockDao;
import com.hctg.forced2sleep.utils.CheckUpdateUtils;
import com.hctg.forced2sleep.utils.MainBottomBarHelper;

public class MainActivity extends BaseActivity<ActivityMainBinding> {

    private final AppLockDao appLockDao = AppLockDao.getInstance(this);
    private MainBottomBarHelper mainBottomBarHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BarUtils.transparentStatusBar(this);
        BarUtils.subtractMarginTopEqualStatusBarHeight(viewBinding.getRoot());
        Intent intent = getIntent();
        if (intent != null) {
            Uri data = intent.getData();
            if (data != null) {
                ToasterUtils.info(data.getAuthority());
                LogUtils.error(data.getAuthority());//传递的内容
            } else {
                LogUtils.error("data == null, from SplashActivity");
            }
        }
        mainBottomBarHelper = new MainBottomBarHelper();
        mainBottomBarHelper.init(viewBinding.viewPager, viewBinding.includeBottomBar);
        mainBottomBarHelper.setOnItemClickListener((v, position) -> {
            viewBinding.viewPager.setCurrentItem(position);
        });
        viewBinding.viewPager.setAdapter(new MainAdapter(getSupportFragmentManager()));



        /**
         * 下面这些是白名单
         */
        /**
         * 添加vivo手机
         */
        addPackageName("android");//系统启动/关机界面
        addPackageName("com.android.BBKClock");//闹钟
        addPackageName("com.android.camera");//拍照
        addPackageName("com.android.contacts");//添加联系人
        addPackageName("com.android.dialer");//拨号,打电话
        addPackageName("com.android.incallui");//拨号中...
        addPackageName("com.android.mms");//信息,短信
        addPackageName("com.android.notes");//便签
        addPackageName("com.android.packageinstaller");//安装app界面
        addPackageName("com.android.server.telecom");//联系人-->个人-->号码分类标记
        addPackageName("com.android.settings");//设置/辅助功能页面
        addPackageName("com.android.stk");//vivo手机弹出的那个超恶心的框框
        addPackageName("com.android.systemui");//锁屏 & 往上滑和往下滑那个
        addPackageName("com.android.wifisettings");//WLAN,wifi设置
        addPackageName("com.alensw.PicFolder");//快图浏览
        addPackageName("com.alibaba.android.rimet");//钉钉
        addPackageName("com.bbk.calendar");//日历
        addPackageName("com.bbk.launcher2");//桌面
        addPackageName("com.bbk.SuperPowerSave");//超级省电界面
//        addPackageName("com.iqoo.powersaving");//超级省电
        //addPackageName("com.iqoo.secure");//通话详情-->加入黑名单&隐私通讯&骚扰拦截&i管家
        addPackageName("com.hctg.forced2sleep");//把自己加进去
        addPackageName("com.vivo.browser");//浏览器
        addPackageName("com.vivo.gallery");//相机相册

        /**
         * 添加华为
         */
        addPackageName("com.huawei.intelligent");
        addPackageName("com.huawei.android.launcher");//华为桌面

        /**
         * 添加第三方
         */
        addPackageName("com.autonavi.minimap");//高德地图
        addPackageName("com.eg.android.AlipayGphone");//支付宝
        addPackageName("com.kuchuan.getsign");//酷川云获取签名
        addPackageName("com.MobileTicket");//铁路12306
        addPackageName("com.starrymedia.metro.best");//最地铁
        addPackageName("com.tc.cm");//地铁通
        addPackageName("com.tencent.androidqqmail");//腾讯邮箱
        addPackageName("com.tencent.mm");//微信
        addPackageName("com.tencent.mobileqq");//QQ

        //检查更新
        new CheckUpdateUtils().check(this);

        // TODO: 2024/4/18 是否能增加设备管理器, 防卸载
        //检测root, 模拟器 等
        boolean isRoot = DeviceUtils.isDeviceRooted();
        boolean isEmulator = DeviceUtils.isEmulator();
    }

    @Override
    public void onViewClicked(View view) {
        switch (view.getId()) {
//            case R.id.btn: //确定
//                startActivity(new Intent(mActivity, EnterPwdActivity.class));
//                break;
//            case R.id.btn_host_manage://手机Host管理
//                startActivity(new Intent(this, HostManageActivity.class));
//                break;
//            default:
//                break;
        }
    }

    private void addPackageName(String packageName){
        if (!appLockDao.find(packageName)) {
            appLockDao.add(packageName);
        }
    }
}
